home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d23 / check_os.arc / CHECK-OS.PAS < prev    next >
Pascal/Delphi Source File  |  1988-03-06  |  4KB  |  128 lines

  1. program CheckOS;
  2.  
  3. { This program was written to be compiled with Turbo Pascal version 4.0.  It }
  4. { checks the Filesize, File Date/Time (last updated), and Checksum of        }
  5. { COMMAND.COM, AUTOEXEC.BAT, and CONFIG.SYS.  It was developed to verify     }
  6. { that no virus had installed itself in DOS.  It does not stay resident to   }
  7. { guard against Viruses, it just checks the specified drive once when the    }
  8. { program is invoked.  It also doesn't have terribly extensive error         }
  9. { checking so little things like the disk being too full to create the       }
  10. { Control file, or a Write protect error will cause a runtime error.  I      }
  11. { didn't feel it was necessary to fix these since I only use the program on  }
  12. { my hard disk.                                                              }
  13. {                                                                            }
  14. { No warranty is given with this software - use at your own risk.            }
  15. {                                                                            }
  16. { R.J. Bartlett  05 March 1988    GEnie address R.BARTLETT                   }
  17.  
  18. {$R-,S-,I+,D+,T-,F-,V-,B-,N-,L+}
  19. {$M 8192,0,0}
  20.  
  21. uses
  22.    dos, crt;
  23. type
  24.    frec = record fsize, ftime : longint; fchksum : word; end;
  25. const
  26.    FileName : array[1..3] of string[20] = (':\COMMAND.COM',
  27.                                            ':\CONFIG.SYS',
  28.                                            ':\AUTOEXEC.BAT');
  29. var
  30.    parm    : string[80];
  31.    NewRec  : array[1..3] of frec;
  32.    CtlRec  : array[1..3] of frec;
  33.    CtlFile : file of frec;
  34.    I       : integer;
  35.    Buffer  : array[1..4096] of byte;
  36.    ErrFlag : boolean;
  37.    Drive   : char;
  38.  
  39.  
  40. function ChkSumBlock(Count, OldChkSum : word) : word;
  41. var
  42.    I, ChkSum : word;
  43. begin
  44.    ChkSum := OldChksum;
  45.    for I := 1 to count do ChkSum := ChkSum + (Buffer[I] xor I);
  46.    ChkSumBlock := ChkSum;
  47. end;
  48.  
  49.  
  50. procedure ChkFile(Ndx : word);
  51. var
  52.    f      : file;
  53.    cnt    : word;
  54. begin
  55.    assign(f, Drive + FileName[Ndx]);
  56.    reset(f,1);
  57.    NewRec[Ndx].fsize := filesize(f);
  58.    getftime(f, NewRec[Ndx].ftime);
  59.    NewRec[Ndx].fchksum := 0;
  60.    repeat
  61.       blockread(f, Buffer, 4096, cnt);
  62.       NewRec[I].fchksum := chksumblock(cnt, NewRec[I].fchksum);
  63.    until (cnt < 1024);
  64.    close(f);
  65. end;
  66.  
  67.  
  68. procedure WrtError(ErrMsg : string; fnum : word);
  69. begin
  70.    writeln(ErrMsg,' mismatch on file ', Drive, FileName[fnum]);
  71.    ErrFlag := true;
  72. end;
  73.  
  74.  
  75. procedure ValidateFiles;
  76. var
  77.    I   : integer;
  78.    ch  : char;
  79. begin
  80.    ErrFlag := false;
  81.    for I := 1 to 3 do
  82.    begin
  83.       read(CtlFile, CtlRec[I]);
  84.       if CtlRec[I].fsize <> NewRec[I].fsize then WrtError('File size',I);
  85.       if CtlRec[I].ftime <> NewRec[I].ftime then WrtError('Date/Time',I);
  86.       if CtlRec[I].fchksum <> NewRec[I].fchksum then WrtError('Checksum ',I);
  87.    end;
  88.    if ErrFlag then
  89.    begin
  90.       writeln;
  91.       writeln('Check-OS has determined that the file (or files) listed above');
  92.       writeln('have been changed since the last time Check-OS was run.');
  93.       writeln(#7);
  94.       writeln('Do you wish to update the Check-OS control file (\Check-OS.CTL)');
  95.       write('to reflect new values (Y or N)? ');
  96.       ch := readkey;
  97.       writeln(ch);
  98.       if upcase(ch) = 'Y' then
  99.       begin
  100.          rewrite(CtlFile);
  101.          for I := 1 to 3 do write(CtlFile, NewRec[I]);
  102.       end;
  103.    end else writeln('Check-OS found no errors');
  104. end;
  105.  
  106.  
  107. begin
  108.    assign(output,'');  { this allows redirection even though CRT unit is used }
  109.    rewrite(output);
  110.    writeln('Check-OS       Version 1.0a    05 March 88'#13#10);
  111.    if (ParamCount < 1) then writeln('Usage -> Check-OS drive ')
  112.    else
  113.    begin
  114.       parm := paramstr(1);
  115.       Drive := upcase(parm[1]);
  116.       for I := 1 to 3 do ChkFile(I);
  117.       assign(CtlFile, Drive + ':\CHECK-OS.CTL');
  118.       {$I-} reset(CtlFile); {$I+}
  119.       if (ioresult = 0) then ValidateFiles
  120.       else
  121.       begin
  122.          rewrite(CtlFile);
  123.          for I := 1 to 3 do write(CtlFile, NewRec[I]);
  124.          writeln('Control file created');
  125.       end;
  126.       close(CtlFile);
  127.    end;
  128. end.